package cn.doyens.reggie.test;

import org.springframework.beans.BeanUtils;

import java.io.Serializable;

public class BeanUtilsDemo {

    public static void main(String[] args) {

        Dish1 person = new Dish1("zhangsan",18);

        DishDto worker = new DishDto();

        //将person对象中的字段值 快速赋值给worker对象中的 相关字段
        BeanUtils.copyProperties(person,worker);

        worker.sex = "男";

        System.out.println(person);
        System.out.println(worker);




    }
}

class Dish1 implements Serializable{
    String name;
    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Dish1() {
    }

    public Dish1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class DishDto extends Dish1 implements Serializable {
    String sex;

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}
